
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  pool.bean;


import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;
import dbmanager.DBManager;

import pool.tablename.Trans_property_details;
import utility.ConvertToLower;


public class Trans_property_details_Bean extends SubBean
{
		
	private Vector<Object> TpdPropertyVector = new Vector<Object>();
	
	private Hashtable<Object,Object> newTransactionHash;
	private Hashtable<Object,Object> oldTransactionHash;
	
	private String tid;
	private String tableName = "trans_property_details";	
	
	private Trans_property_details objTpd;
	
	private Vector<Object> OldTransPropertyVector = new Vector<Object>();
	private Vector<Object> NewTransPropertyVector = new Vector<Object>();
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	PoolLogger pl;
	
	public Trans_property_details_Bean() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
		
	public void setId(String id)
	{
		this.tid = id ;
	}
	
	
	/**
	 *  this function adds hashtable having property in vector in Trans_property_details class format
	 * @param PropertyHash contains property of transaction
	 * TpdPropertyVector vector of properties of Trans_property_details
	 */
	
	public void setPropertyVector(Hashtable<Object,Object> PropertyHash)
	{
		Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
		propertyHash.putAll(PropertyHash);
		propertyHash=gin.ConvertPVtoVT(propertyHash);
		propertyHash = gin.convertMasterId(propertyHash,tableName,process);
		
		TpdPropertyVector.add(propertyHash);		
	}
	
	
	/**
	 * this function converts properties in vector in Trans_property_details class format to insert
	 * @param vector containing properties
	 */
	@SuppressWarnings("unchecked")
	public void setPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{			
			Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
			propertyHash.putAll((Hashtable<Object, Object>)object);
			propertyHash=gin.ConvertPVtoVT(propertyHash);
			propertyHash = gin.convertMasterId(propertyHash, tableName,process);
			TpdPropertyVector.add(propertyHash);			
		}		
	}
	
	
	/**
	 * Insert into Trans_property_details
	 * @return 
	 *
	 */
	@SuppressWarnings("unchecked")
	public StringBuffer insert()
	{
		DBManager.setBeforeCommit();
		objTpd = new Trans_property_details();
		objTpd.initPool();
		objTpd.setRequestParameter(reqParam);
		
		StringBuffer sbrDTB = new StringBuffer();
		
		objTpd.setTid(tid);
		objTpd.setPropertyVector(TpdPropertyVector);
		sbrDTB.append(objTpd.getInsert());
		
		boolean flag = objTpd.getResult();
		DBManager.setAfterCommit(flag);
		
		System.out.println(sbrDTB.toString());
		pl.info(sbrDTB.toString());
		pl.debug(sbrDTB.toString());
		pl.warn(sbrDTB.toString());
		pl.fatal(sbrDTB.toString());
		pl.error(sbrDTB.toString());
		pl.trace(sbrDTB.toString());
		
		return sbrDTB;
		
	}
	
	
	/**
	 * 
	 * @param oldPropertyHash is Hashtable of old property of Trans_property_details.  
	 */	
	public void setOldPropertyHash(Hashtable<Object,Object> oldPropertyHash)
	{
		
		objTpd=new Trans_property_details();
		objTpd.setRequestParameter(reqParam);
		oldTransactionHash = new Hashtable<Object, Object>();
		oldTransactionHash.putAll(oldPropertyHash);
		oldTransactionHash=ConvertToLower.convertHashKey(oldTransactionHash);
		oldTransactionHash=gin.ConvertPVtoVT(oldTransactionHash);
		oldTransactionHash = gin.convertMasterId(oldTransactionHash, tableName,process);
		tid=oldTransactionHash.get("tid").toString();
		OldTransPropertyVector.add(oldPropertyHash);
		
		
	}
	
	
	/**
	 * 
	 * @param newPropertyHash  Hashtable of new property of Trans_property_details to update  
	 */
	public void setNewPropertyHash(Hashtable<Object,Object> newPropertyHash)
	{
		newTransactionHash = new Hashtable<Object, Object>();
		newTransactionHash.putAll(newPropertyHash);
		newTransactionHash=ConvertToLower.convertHashKey(newTransactionHash);
		newTransactionHash=gin.ConvertPVtoVT(newTransactionHash);
		newTransactionHash = gin.convertMasterId(newTransactionHash, tableName,process);
		NewTransPropertyVector.add(newTransactionHash);
	
	}
	
	
	/**
	 * this function converts old properties of vector in Trans_property_details class format to update
	 * @param vector containing old properties
	 */
	@SuppressWarnings("unchecked")
	public void setOldPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{
			Hashtable<Object,Object> hasht = (Hashtable<Object, Object>)object;
			setOldPropertyHash(hasht);
		}
	}
	
	
	/**
	 * this function converts new properties of vector in Trans_property_details class format to update
	 * @param vector containing new properties
	 */
	@SuppressWarnings("unchecked")
	public void setNewPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{
			Hashtable<Object,Object> hasht = (Hashtable<Object, Object>)object;
			setNewPropertyHash(hasht);
		}
	
	}
	
	/**
	 * Update  Trans_property_details
	 * @return stringbuffer containing details of updation
	 */
	public StringBuffer update()
	{
		DBManager.setBeforeCommit();
		StringBuffer sbrDTB = new StringBuffer();
		objTpd = new Trans_property_details();
		objTpd.setRequestParameter(reqParam);
		
		if(!OldTransPropertyVector.isEmpty())
			objTpd.setOldPropertyVector(OldTransPropertyVector);
		
		if(!NewTransPropertyVector.isEmpty())
			objTpd.setNewPropertyVector(NewTransPropertyVector);
		
		sbrDTB.append(objTpd.getUpdate());
		
		boolean flag = objTpd.getResult();
		DBManager.setAfterCommit(flag);
		
		System.out.println(sbrDTB.toString());
		pl.info(sbrDTB.toString());
		pl.debug(sbrDTB.toString());
		pl.warn(sbrDTB.toString());
		pl.fatal(sbrDTB.toString());
		pl.error(sbrDTB.toString());
		pl.trace(sbrDTB.toString());
		
		return sbrDTB;
	}
	
	
	/**
	 * this function converts hashtable to Trans_property_details class format for view
	 * @param hashtable contains property
	 */
	public void setViewHashtable(Hashtable<Object,Object> hashtable)
	{

		Hashtable<Object,Object> PropertyHash = new Hashtable<Object, Object>();
		
		PropertyHash.putAll(hashtable);
		PropertyHash = gin.ConvertPVtoVT(PropertyHash);
		PropertyHash.putAll(gin.getHashMapOfValues(PropertyHash));
		PropertyHash.putAll(ConvertToLower.convertHashKey(PropertyHash));
		PropertyHash = gin.convertMasterId(PropertyHash,tableName,process);		
		PropertyHash.putAll(gin.getHashMapOfValues(PropertyHash));	
		
		ViewHashtable.putAll(PropertyHash);	
	}
	
	
	/**
	 * view() calls getView() of Trans_property_details class
	 * @return stringbuffer containing details of properties in message format
	 */	
	public StringBuffer view()
	{
		StringBuffer sbrDTB = new StringBuffer();
		objTpd = new Trans_property_details();
		objTpd.setRequestParameter(reqParam);
		objTpd.setViewHashtable(ViewHashtable);
		
		sbrDTB.append(objTpd.getView());
		System.out.println(sbrDTB.toString());		
		pl.info(sbrDTB.toString());
		pl.debug(sbrDTB.toString());
		pl.warn(sbrDTB.toString());
		pl.fatal(sbrDTB.toString());
		pl.error(sbrDTB.toString());
		pl.trace(sbrDTB.toString());
		
		return sbrDTB;
	
	}
	
	
	public Vector<Object> getPropertyVector()
	{
		return TpdPropertyVector;
	}

	@Override
	public StringBuffer delete() {
		// TODO Auto-generated method stub
		return null;
	}
	
		
	/*
	public void setOldTransactionHash(Hashtable<Object,Object> oldPropertyHash)
	{
		oldTransactionHash.putAll(oldPropertyHash);
	}*/
	
	/*public static void main(String[] args) 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		Trans_property_details_Bean prop = new Trans_property_details_Bean();
		prop.setDBManager();
		Hashtable<Object, Object> old = new Hashtable<Object, Object>();
		old.put("tid", "5");
		old.put("pid", "reference");
		old.put("pv", "vcvvccvccc");
		
		Hashtable<Object, Object> newHash = new Hashtable<Object, Object>();
		newHash.put("tid", "5");
		newHash.put("pid", "reference");
		newHash.put("pv", "vgbnmnmgnvm");
		
		
		RequestParameter req = new RequestParameter();
		req.setUsername("+919922930640");
		req.setMessage("System Message");
		req.setPassword("123");
		req.setRequest("trans_property_details");
		req.setProcess("add");
		
	
		prop.setReqParam(req);
		prop.setReqParam(req);
		
		prop.setPropertyVector(old);
		prop.setOldPropertyHash(old);
		prop.setNewPropertyHash(newHash);
	
		//prop.insertTrans_property_details();
		prop.updateTrans_property_details();
		db.closeConnection();
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Trans_property_details_Bean","main",t.duration());
	}*/
	
	
	
}
